package com.tiyende.kash.loop.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.tiyende.kash.loop.R
import org.json.JSONObject

/**
 * 引导页适配器
 */
class TiyendeGuidePagerAdapter(private val slides: List<JSONObject>) : RecyclerView.Adapter<TiyendeGuidePagerAdapter.GuideViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GuideViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.tiyende_activity_guide_item, parent, false)
        return GuideViewHolder(view)
    }
    override fun onBindViewHolder(holder: GuideViewHolder, position: Int) {
        val slide = slides[position]
        holder.bind(slide)
    }
    override fun getItemCount(): Int = slides.size
    class GuideViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val imgGuideIcon = itemView.findViewById<ImageView>(R.id.imgGuideIcon)
        fun bind(model: JSONObject) {
            imgGuideIcon.setImageResource(model.optInt("icon"))
        }
    }
}